import React,{Component} from 'react';
import ReactDOM, { render } from 'react-dom';
import {createStore,applyMiddleware} from 'redux'; //createStore创建一个仓库，用来处理数据= {}
import thunk from 'redux-thunk';
import fetchReducer from './fetchReducer';

//step1 构建一个仓库
const store = createStore(fetchReducer, applyMiddleware(thunk));

const getData = postTitle => (dispatch, getState) => {
	dispatch({
		type: postTitle + "_START"
    });
    //fetch ----ajax-----axios
    // 做异步处理，比如ajax，在回调中再次dispatch
    fetch('http://api.douban.com/v2/movie/top250')
    .then(res=>{
        console.log(res)
        return res.json()
    })
    .then(data=>{
        dispatch({
            type:postTitle + '_FINISH',
            payload:data
        })
    })
};
